package com.malty.utils.innerclass;

interface IA {
    void cry();
}

public class AnonymousInnerClass {
    public static void main(String[] args) {
        Outer04 outer04 = new Outer04();
        outer04.method();
    }
}

class Outer04 {
    private int n1 = 10;

    public void method() {
        // 匿名内部类使用后就不能再使用了
        IA tiger = new IA() {
            @Override
            public void cry() {
                System.out.println("老虎叫唤");
                // 匿名内部类 系统会分配一个类名 Outer04$1
                System.out.println(this.getClass());
            }
        };
        tiger.cry();

        tiger = new IA() {
            @Override
            public void cry() {
                System.out.println("新老虎");
            }
        };
        System.out.println(tiger.getClass());

        Father father = new Father("jack") {
            @Override
            public void test() {
                System.out.println("重写了father的test方法");
            }
        };
        father.test();
        System.out.println("---->" + father.getClass());
        Animal animal = new Animal() {
            @Override
            void eat() {
                System.out.println("小哥吃骨头");
            }
        };
    }
}

class Father {

    public Father(String name) {
        System.out.println("接收到name "+name);
    }

    public void test() {
        System.out.println("father的test方法");
    }
}

abstract class Animal {
    abstract void eat();
}